//
// Created by fh on 2021/6/23.
//

#include "RecursionAnalyse.h"

/* 全排列 */
void printPermutations(int data[],int n,int k) {
    printf("k --------------------------------------- %d\n",k);
    if (k == 1) {
        for (int i = 0; i < n; ++i) {
            printf("%d ",data[i]);
        }
        printf("\n");
    }

    for (int i = 0; i < k; ++i) {
        int tmp = data[i];
        data[i] = data[k-1];
        data[k-1] = tmp;

        printPermutations(data,n,k-1);

        tmp = data[i];
        data[i] = data[k-1];
        data[k-1] = tmp;
    }

}

void RecursionAnalyseDemo() {
    int a[] = {1,2,3,4};
    int length = sizeof(a)/ sizeof(int);
    printPermutations(a,length,length);
}